﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsaGame1
{
    class Personagem : AnimatedObject
    {

        KeyboardState teclado;
        KeyboardState tecladoAntigo;
        MouseState mouse;
        MouseState mouseAntigo;
        bool controleAnimacao;

        //Texture2D texturaTiro;
        //public List<Tiro> listaTiros;


        public Personagem(Texture2D texture,int Width,int Height)
            : base(texture,Width,Height)
        {
            //this.texturaTiro = texturaTiro;
            //listaTiros = new List<Tiro>();


            AnimationStructure animationCorrendo = new AnimationStructure();
            animationCorrendo.frameCount = 4;
            animationCorrendo.frameWidth = Width;
            animationCorrendo.frameHeight = Height;
            animationCorrendo.framePerSecond = 20;
            animationCorrendo.X = 0;
            animationCorrendo.Y = 0;

            //AnimationStructure animationAgachando = new AnimationStructure();
            //animationAgachando.frameCount = 1;
            //animationAgachando.frameWidth = Width;
            //animationAgachando.frameHeight = Height;
            //animationAgachando.framePerSecond = 10;
            //animationAgachando.X = 288;
            //animationAgachando.Y = 32;
            //listaAnimations.Add("agachando", animationAgachando);

            //AnimationStructure animationPular = new AnimationStructure();
            //animationPular.frameCount = 1;
            //animationPular.frameWidth = Width;
            //animationPular.frameHeight = Height;
            //animationPular.framePerSecond = 10;
            //animationPular.X = 192;
            //animationPular.Y = 32;
            //listaAnimations.Add("pular", animationPular);


            //ChangeAnimation("correndo");
            //startY = posicao.Y;
            //jumping = false;
            //jumpspeed = 0;

            //velocidadePulo = new Vector2(0, -3);


            listaAnimations.Add("correndo", animationCorrendo);

            ChangeAnimations("correndo");

        }

        public override void Update(GameTime gameTime)
        {
            teclado = Keyboard.GetState();
            mouse = Mouse.GetState();

            //criar um codigo pra mante a nave na tela
            
            if (teclado.IsKeyDown(Keys.Left))
            {

                //a nave esta encostando no canto esquerdao da tela?
                //se sim coloque ela no canto maximo da tela
                //se não faça
                
                posicao.X -= 5;
               
            }
             if (teclado.IsKeyDown(Keys.Right))
            {
                posicao.X += 5;
                
            }
             

             if (teclado.IsKeyDown(Keys.Up))
            {
                posicao.Y -= 5;
                
            }
          if (teclado.IsKeyDown(Keys.Down))
            {
                posicao.Y += 5;
                
            }

          if ((teclado.IsKeyUp(Keys.Right) && teclado.IsKeyUp(Keys.Left)))
          {
              ChangeAnimations("default");
          }

            if (mouse.LeftButton == ButtonState.Pressed &&
                mouseAntigo.LeftButton == ButtonState.Released)
            {
                //Tiro tiro = new Tiro(texturaTiro);
                //tiro.posicao = this.posicao;
                //listaTiros.Add(tiro);

                TiroManager.AddTiro(this.posicao, 0);
               ChangeAnimations("correndo");
            }

            //for (int i = 0; i < listaTiros.Count; i++)
            //{
            //    listaTiros[i].Update();
            //}

            //BoundingSphere esfera = new BoundingSphere();
            //esfera.

         //   else 
              //  ChangeAnimations("default");

            if (controleAnimacao == true)
            {
                ChangeAnimations("default");
                controleAnimacao = false;
            }


             if (frame == 3)
             { 
                
                controleAnimacao = true;
             }


            //for (int i = 0; i < listaTiros.Count; i++)
            //{
            //    listaTiros[i].Update();
            //}

            //BoundingSphere esfera = new BoundingSphere();
            //esfera.

            tecladoAntigo = teclado;
            mouseAntigo = mouse;

            base.Update(gameTime);

        }

    }
}
